
package com.fivebrms.view.confidentiality
{
	import org.osflash.thunderbolt.Logger;
	
	import mx.controls.Button;
	import mx.controls.TextInput;
	import mx.containers.VBox;
	
	import mx.binding.utils.BindingUtils;
	
	import mx.validators.StringValidator;
	
	import com.fivebrms.model.MainModelLocator;
	
	import mx.events.FlexEvent;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import com.fivebrms.events.ConfidentialityEvent;
	import com.fivebrms.vo.ConfidentialityVO;
	
	public class FormFields extends VBox
	{
		private var model : MainModelLocator;
		
		//
		// form fields from the formFields.mxml file
		//
		public var inp_vendorSignature : TextInput;
		public var inp_vendorCode : TextInput;
		public var btn_submitConfidForm : Button;
		
		private var confidVO : ConfidentialityVO;
		
		//
		// constructor
		//
		public function FormFields()
		{
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
		}
		
        private function creationCompleteHandler(event:FlexEvent) : void
        {
            Logger.info("confidentiality add event listeners..");
            
			this.model = MainModelLocator.getInstance();

			btn_submitConfidForm.addEventListener(MouseEvent.CLICK, buttonPressedHandler);

			this.validateForm();
		}

		private function buttonPressedHandler(event : MouseEvent ) : void
		{
            Logger.info("you clicked the btn_submitConfidForm button!!!");
            
            //
            // validate form before submitting
            //
            this.validateForm();
            
            //
            // submit the confidentiality form to the server
            //            
            var confidEvent : ConfidentialityEvent = new ConfidentialityEvent( );
            confidEvent.dispatch();
          
            Logger.info("done  btn_submitConfidForm event..!");
		}

		private function validateForm() : void
		{
			this.confidVO = this.model.confidentialityVO;
			
            Logger.info("this.inp_vendorSignature.text.." + this.inp_vendorSignature.text);
            Logger.info("this.inp_vendorCode.text.." + this.inp_vendorCode.text);
			
			this.confidVO.vendorName = this.inp_vendorSignature.text;
			this.confidVO.vendorCode = this.inp_vendorCode.text;
        }

	}
}

